|
|
|
|
|
|
|
Because there is no Table2 in ERRORDB.MDB, you see a database error when the program runs. The error message is displayed, and then the form is unloaded completely (see Figure 14.15). |
|
|
|
|
|
|
|
|
Figure 14.15.
Displaying an error message
from the Form_Load event. |
|
|
|
|
|
|
|
|
It is a good idea to open any data tables or files that you need for a data entry form during the Form_Load event. That way, if there are problems, you can catch them before data entry begins. |
|
|
|
|
|
|
|
|
Creating Your Error Handler OLE Server |
|
|
|
|
|
|
|
|
In the previous sections, you created several error handlers, each tuned to handle a special set of problems. Although this approach works for small projects, it can be tedious and burdensome if you have to put together a large application. Also, after you've written an error handler that works well for one type of error, you can use that error handler in every other program that might have the same error. Why write it more than once? |
|
|
|
|
|
|
|
|
Even though Visual Basic requires error traps to be set for each Sub or Function, you can still create a generic approach to error handling that takes advantage of code you have already written. In this section, you write a set of routines that you can install in all your Visual Basic programsthe error-handling OLE Server. This OLE Server offers some generic error-handling capabilities along with the ability to log these errors to a disk file and to keep track of the procedure call stack. These last two services can be very valuable when you encounter a vexing bug in your program and need to get additional information on the exact subroutines and functions that were executed before the error occurred. |
|
|
|
|
|
|
|
|
To build the new error handling OLE Server, you need to start a new Visual Basic ActiveX DLL project. Name the default Class module errHandler and set the project Name to prjErrHandler. You also need to add a BAS module and a form to the project. The form acts as the new customized error dialog box. The BAS module holds a new user-defined type and some API definitions for use with the customized error dialog box. |
|
|
|
|
|
|
|
|
Building the errHandler Class |
|
|
|
|
|
|
|
|
Building the errHandler class involves several steps. First, add some code to the general declaration section of the Class object (see Listing 14.13). |
|
|
|
|
|